package com.example.luke.cashorderingsystem.Activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.luke.cashorderingsystem.Adapter.GridViewAdapter;
import com.example.luke.cashorderingsystem.Common.CommonActivity;
import com.example.luke.cashorderingsystem.Common.Setting;
import com.example.luke.cashorderingsystem.Dialog.DevIdDialog;
import com.example.luke.cashorderingsystem.Dialog.InternetSettingDialog;
import com.example.luke.cashorderingsystem.R;
import com.example.luke.cashorderingsystem.Util.GlobalFunction;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by luke on 11/24/16.
 */

public class SystemSettingActivity extends CommonActivity {

   DevIdDialog devIdDialog;
    @InjectView(R.id.option_menu)GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.system_setting_activity_layout);
        showBackButton();
        setBarTitle(GlobalFunction.getString(this,R.string.systemSetting));
        initView();

    }

    @Override
    public void initView() {
        super.initView();
        ButterKnife.inject(this);

        Integer [] images={R.drawable.setting_internet,R.drawable.setting_language};
        String[] titles={"网络设置","语言"};

        gridView.setAdapter(new GridViewAdapter(this, images,titles));
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                switch (view.getId()) {





                    case R.drawable.setting_internet:

                        settingIntenet();

                        break;



                    case R.drawable.setting_language:

                           settingLanID();

                        break;


                }
            }
        });


//        devIdDialog=new DevIdDialog(Setting.getInstance().getDevID(),this);
//
//
//        devIdDialog.setDialogListener(new DevIdDialog.DialogListener() {
//            @Override
//            public void optionSelected(String option) {
//                devID.setText(option);
//                Setting.getInstance().setDevID(option);
//                Setting.getInstance().saveDevID();
//
//            }
//        });
//        devID.setText(Setting.getInstance().getDevID());
    }


    public void settingDevID(View v){

       devIdDialog.show();

    }

    public void settingLanID(){

        final String[]lanKey=getResources().getStringArray(R.array.lanKey);
        final AlertDialog.Builder builder= new AlertDialog.Builder(this);
        final String[] dialogItems=getResources().getStringArray(R.array.lanKeyVal);

        builder.setTitle(GlobalFunction.getString(this,R.string.Language)).setItems(dialogItems, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            GlobalFunction.setLanKey(SystemSettingActivity.this,lanKey[which]);
            initLanguage(lanKey[which]);

                restart();

            }
        });
        builder.show();




    }

    private void settingIntenet(){

        InternetSettingDialog internetSettingDialog=new InternetSettingDialog(this);
        internetSettingDialog.show();

    }


    public void logOut(View view){

        Intent intent=new Intent(this,LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);


    }


}
